// 定义 PiniaStore 模块
import { defineStore } from 'pinia'
// 导入 axios
import axios from 'axios'
import { ChannelsList, ChannelsRes } from '../../types'


export const useChannelsStore = defineStore('channels', {
    state: () => ({
        channelsList: [] as ChannelsList,
        active: -1
    }),
    actions: {
        // 获取频道列表
        async getChannels() {
            const res = await axios.get<ChannelsRes>('/api/channels')
            this.channelsList = res.data.result.list

            this.active = this.channelsList[0].hotindex
        },
        changeActive(index: number) { this.active = index }
    },
    getters: {

    }
})